﻿// Copyright (c) 2007-2020 西安交通信息投资营运有限公司 版权所有
// 作者:吕艳阳

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Threading.Tasks;
using System.Windows.Forms;
using XCI.Core;
using XCI.Helper;

namespace XCI.Windows
{
    public class FormCaptionPopupGridControlEdit : PopupGridControlEdit,IAsyncBindingData
    {
        public override string Id => "grid-ed8b16c699b34dbb9501f246ca2b061c";
        public override string DisplayMember => "Code";
        public override string ValueMember => "Code";
        public override bool IsSelectFirstRow => false;
        public override Size PopupSize => new Size(0, 400);
        public override Type ModelType => typeof(FormCaptionAttribute);
 
        /// <summary>
        /// 异步绑定数据
        /// </summary>
        /// <returns>等待的任务</returns>
        public virtual async Task BindingDataAsync()
        {
            if (this.IsDisposing || this.IsDisposed) return;
            var list = await Task.Factory.StartNew(GetProviders);
            base.DataSource = list;
        }

        private List<FormCaptionAttribute> GetProviders()
        {
            return WinFormHelper.GetComponentCaptionProvider<FormCaptionAttribute>(p => ObjectHelper.CheckSubClass(p, new[] { typeof(Form) }));
        }
    }
}